home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0159_Font Creation Program.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  8KB  |  309 lines

  1. {
  2. I managed to write a unit called Fonts that will allow you to customise your
  3. EGA/VGA character sets and fonts like it is done in the Norton Utilities, save
  4. and restore them easily. There are given some different sizes for fonts:
  5.  
  6. 8x8        (VGA mode 80x50 or EGA mode 80x43)
  7. 8x14       (EGA mode 80x25)
  8. 8x16       (VGA mode 80x25)
  9. and
  10. 9x16 (not currently supported)
  11.  
  12. Each character represents the matrix with length of 8, 14, or 16 bytes. Here is
  13. the table for 8x8, 8x14 and 8x16 fonts, respectively:
  14.  
  15. 8x8 font        8x14 font       8x16 font
  16.  
  17. 00000000        00000000        00000000
  18. 00000000        00000000        00000000
  19. 00000000        00000000        00000000
  20. 00000000        00000000        00000000
  21. 00000000        00000000        00000000
  22. 00000000        00000000        00000000
  23. 00000000        00000000        00000000
  24. 00000000        00000000        00000000
  25.                 00000000        00000000
  26.                 00000000        00000000
  27.                 00000000        00000000
  28.                 00000000        00000000
  29.                 00000000        00000000
  30.                 00000000        00000000
  31.                                 00000000
  32.                                 00000000
  33.  
  34. So for 8x8 font there is array[0..255,1..8] of Byte, for 8x14 -
  35. array[0..255,1..14] of Byte, and for 8x16 - array[0..255,1..16] of Byte.
  36.  
  37. How to reprogram a ASCII character so it will look 'as you would like it to
  38. be'?
  39.  
  40. Single scan line of each character of any font type consists of 8 bits (1
  41. byte) each. Each font (as said earlier) has 8, 14, or 16 scan lines and will
  42. occupy whether 256*8=2048, 256*14=3584, or 256*16=4096 bytes (since there are
  43. 0..255=256 bytes in the ASCII table).
  44.  
  45. To define your own 'A' letter, for example, in font 8x8 you would need:
  46.  
  47. 1. To define first your own 8x8 matrix for 'A' character like shown below:
  48.  
  49. 00011111   hex 1F
  50. 00110011   hex 33
  51. 01100011   hex 63
  52. 11000011   hex C3
  53. 11000011   hex C3
  54. 11111111   hex FF
  55. 11000011   hex C3
  56. 11000011   hex C3
  57.  
  58. 2. To replace active matrix of character 'A' with the new one using the Fonts
  59. unit do the following:
  60.  
  61. Define a new 'A' character matrix for 8x8. NewA contains the buffer to load
  62. matrix from
  63.  
  64. const
  65.   NewA : array[1..8] of Byte = ($1F, $33, $63, $C3, $C3, $FF, $C3, $C3);
  66.  
  67. Begin
  68.   LoadCharset(NewA, Ord('A'), 1, 8)
  69. End.
  70.  
  71. }
  72.  
  73. Unit Fonts;
  74. { Copyright (c) 1994 by Andrew Eigus  Fidonet: 2:5100/33 }
  75. { Public Domain, ready for SWAG }
  76.  
  77. (*
  78.   This unit provides EGA/VGA font management routines and enables you
  79.   to save/restore characters or charsets and also makes it easy for you
  80.   to set your own (custom) characters or charsets in EGA/VGA modes
  81.  
  82.   8x8 font:  for EGA 80x43 or VGA 80x50 modes,
  83.   8x14 font: for EGA 80x25 mode,
  84.   8x16 font: for VGA 80x25 mode
  85. *)
  86.  
  87. interface
  88.  
  89. type
  90.   { 8x8 font table type }
  91.   P8x8Charset = ^T8x8Charset;
  92.   T8x8Charset = array[0..255, 1..8] of Byte;
  93.  
  94.   { 8x14 font table type }
  95.   P8x14Charset = ^T8x14Charset;
  96.   T8x14Charset = array[0..255,1..14] of Byte;
  97.  
  98.   { 8x16 font table type }
  99.   P8x16Charset = ^T8x16Charset;
  100.   T8x16Charset = array[0..255, 1..16] of Byte;
  101.  
  102. const
  103.   { ROM table pointer request codes to use with #SaveROMFont#: }
  104.  
  105.   reqInt1F = 0; { return current Int 1Fh graphics font address }
  106.   reqInt44 = 1; { return current Int 44h graphics font address }
  107.   req8x14  = 2; { return ROM 8x14 font table address }
  108.   req8x8   = 3; { return ROM 8x8 double dot font table address }
  109.   req8x8t  = 4; { return ROM 8x8 double dot address (top) }
  110.   req9x14  = 5; { return ROM 9x14 alternate table address }
  111.   req8x16  = 6; { return ROM 8x16 font table address }
  112.  
  113.  
  114. function EGAInstalled : boolean;
  115. { Determines whether EGA/VGA is installed or not. If EGA/VGA is installed,
  116.   True is returned and you may freely use all of those routines in this
  117.   unit.
  118.  
  119.   See also #GetScanLines# }
  120.  
  121. function GetScanLines : byte;
  122. { Performs auto detection of scan lines per one character in active video
  123.   mode.
  124.  
  125.   for 80x43 EGA or 80x50 VGA mode - 8,
  126.   for 80x25 EGA mode - 14,
  127.   and
  128.   for 80x25 VGA mode - 16 }
  129.  
  130. procedure SaveCharset(var Buffer; StartChar, Count, ScanLines : word);
  131. { Saves Count characters from video memory into Buffer starting with
  132.   StartChar ASCII code and using the ScanLines number for each character
  133.   matrix. To determine number of scan lines in active video font,
  134.   use function #GetScanLines#. (see #SaveFont# procedure) }
  135.  
  136. procedure LoadCharset(var Buffer; StartChar, Count, ScanLines : word);
  137. { Loads Count characters from Buffer into video memory starting with
  138.   StartChar ASCII code and using the ScanLines for each character matrix.
  139.   To determine number of scan lines in active video font,
  140.   use function #GetScanLines#. (see #LoadFont# procedure) }
  141.  
  142. procedure LoadROMCharset(var Buffer; StartChar, Count, ScanLines : word);
  143. { Loads Count characters from ROM charset into video memory starting with
  144.   StartChar ASCII code and using the ScanLines for each character matrix.
  145.   To determine number a number of scan lines in active video font,
  146.   use function #GetScanLines#. }
  147.  
  148. procedure SaveROMFont(var Font; Code : byte);
  149. { Saves ROM font table into Buffer for the specified table pointer
  150.   request code. See ROM table pointer request codes for more information. }
  151.  
  152. procedure SaveFont(var Font; ScanLines : byte);
  153. { Saves the whole active video font into Buffer and uses the value of
  154.   ScanLines to calculate the font size. }
  155.  
  156. procedure LoadFont(var Font; ScanLines : byte);
  157. { Loads the whole into video memory and uses the value of
  158.   ScanLines to calculate the font size. }
  159.  
  160.  
  161. implementation
  162.  
  163. Procedure OpenRegs; near; assembler;
  164. { This is used internally and required by the unit }
  165. Asm
  166.   cli
  167.   mov dx,03C4h
  168.   mov ax,0402h
  169.   out dx,ax
  170.   mov ax,0704h
  171.   out dx,ax
  172.   mov dl,0CEh { port 03CEh }
  173.   mov ax,0204h
  174.   out dx,ax
  175.   mov ax,0005h
  176.   out dx,ax
  177.   mov ax,0406h
  178.   out dx,ax
  179. End; { OpenRegs }
  180.  
  181. Procedure CloseRegs; near; assembler;
  182. { This is used internally and required by the unit. }
  183. Asm
  184.   mov dx,03C4h
  185.   mov ax,0302h
  186.   out dx,ax
  187.   mov ax,0304h
  188.   out dx,ax
  189.   mov dl,0CEh { port 03CEh }
  190.   mov ax,0004h
  191.   out dx,ax
  192.   mov ax,1005h
  193.   out dx,ax
  194.   mov es,Seg0040
  195.   mov ax,0E06h
  196.   cmp byte ptr es:[0049h],07h
  197.   jne @color
  198.   mov ax,0A06h
  199. @color:
  200.   out dx,ax
  201.   sti
  202. End; { CloseRegs }
  203.  
  204. Function EGAInstalled; assembler;
  205. Asm
  206.   mov ax,1200h
  207.   mov bx,0010h
  208.   xor cx,cx
  209.   int 10h
  210.   xor al,al { mov al,False }
  211.   or  cx,0  { still cx the same? yes, there's no EGA }
  212.   jz  @noega
  213.   inc al { al gets True }
  214. @noega:
  215. End; { EGAInstalled }
  216.  
  217. Function GetScanLines; assembler;
  218. Asm
  219.   mov es,Seg0040
  220.   mov al,byte ptr es:[0085h]
  221. End; { GetScanLines }
  222.  
  223. Procedure SaveCharset; assembler;
  224. Asm
  225.   call OpenRegs
  226.   push ds
  227.   mov ax,SegA000
  228.   mov ds,ax
  229.   mov ax,StartChar
  230.   mov bx,32
  231.   mul bx
  232.   mov si,ax
  233.   les di,Buffer
  234.   cld
  235.   mov ax,Count
  236.   mul bx
  237.   mov dx,ScanLines
  238. @@1:
  239.   mov cx,dx
  240.   rep movsb
  241.   mov cx,bx
  242.   sub cx,dx
  243.   add si,cx
  244.   sub ax,bx
  245.   cmp ax,0
  246.   jnz @@1
  247.   pop ds
  248.   call CloseRegs
  249. End; { SaveCharset }
  250.  
  251. Procedure LoadCharset; assembler;
  252. Asm
  253.   call OpenRegs
  254.   push ds
  255.   mov es,SegA000
  256.   mov ax,StartChar
  257.   mov bx,32
  258.   mul bx
  259.   mov di,ax
  260.   mov ax,Count
  261.   mul bx
  262.   mov dx,ScanLines
  263.   lds si,Buffer
  264.   cld
  265. @@1:
  266.   mov cx,dx
  267.   rep movsb
  268.   mov cx,bx
  269.   sub cx,dx
  270.   add di,cx
  271.   sub ax,bx
  272.   cmp ax,0
  273.   jnz @@1
  274.   pop ds
  275.   call CloseRegs
  276. End; { LoadCharset }
  277.  
  278. Procedure SaveROMFont; assembler;
  279. Asm
  280.   mov ax,1130h
  281.   mov bh,Code
  282.   les bp,Font
  283.   int 10h
  284. End; { SaveROMFont }
  285.  
  286. Procedure LoadROMCharset; assembler;
  287. Asm
  288.   mov ah,11h
  289.   xor al,al
  290.   mov cx,Count
  291.   mov dx,StartChar
  292.   xor bl,bl
  293.   mov bh,byte ptr ScanLines
  294.   les bp,Buffer
  295.   int 10h
  296. End; { LoadROMCharset }
  297.  
  298. Procedure SaveFont;
  299. Begin
  300.   SaveCharset(Font, 0, 256, ScanLines)
  301. End; { SaveFont }
  302.  
  303. Procedure LoadFont;
  304. Begin
  305.   LoadCharset(Font, 0, 256, ScanLines)
  306. End; { LoadFont }
  307.  
  308. End.
  309.